<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Token调试页面</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f5f5f5;
        }
        .container {
            background: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        h1 {
            color: #333;
            text-align: center;
            margin-bottom: 30px;
        }
        .debug-section {
            margin-bottom: 20px;
            padding: 15px;
            border: 1px solid #ddd;
            border-radius: 5px;
        }
        .debug-title {
            font-weight: bold;
            margin-bottom: 10px;
            color: #555;
        }
        .debug-content {
            background: #f8f9fa;
            padding: 10px;
            border-radius: 3px;
            font-family: monospace;
            white-space: pre-wrap;
            word-break: break-all;
        }
        button {
            background-color: #007bff;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 14px;
            margin-right: 10px;
            margin-bottom: 10px;
        }
        button:hover {
            background-color: #0056b3;
        }
        .success {
            color: #28a745;
        }
        .error {
            color: #dc3545;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Token调试页面</h1>
        
        <div class="debug-section">
            <div class="debug-title">当前localStorage内容:</div>
            <div class="debug-content" id="localStorageContent"></div>
        </div>
        
        <div class="debug-section">
            <div class="debug-title">Token状态:</div>
            <div class="debug-content" id="tokenStatus"></div>
        </div>
        
        <button onclick="refreshDebug()">刷新调试信息</button>
        <button onclick="clearAll()">清除所有数据</button>
        <button onclick="testTokenSave()">测试Token保存</button>
        <button onclick="testTokenRead()">测试Token读取</button>
        
        <div class="debug-section">
            <div class="debug-title">操作日志:</div>
            <div class="debug-content" id="operationLog"></div>
        </div>
    </div>

    <script>
        function log(message) {
            const logDiv = document.getElementById('operationLog');
            const timestamp = new Date().toLocaleTimeString();
            logDiv.textContent += `[${timestamp}] ${message}\n`;
        }
        
        function refreshDebug() {
            // 显示localStorage内容
            const localStorageContent = document.getElementById('localStorageContent');
            let content = '';
            for (let i = 0; i < localStorage.length; i++) {
                const key = localStorage.key(i);
                const value = localStorage.getItem(key);
                content += `${key}: ${value}\n`;
            }
            localStorageContent.textContent = content || 'localStorage为空';
            
            // 显示Token状态
            const tokenStatus = document.getElementById('tokenStatus');
            const token = localStorage.getItem('token');
            const userType = localStorage.getItem('userType');
            const loginTime = localStorage.getItem('loginTime');
            
            if (token) {
                tokenStatus.innerHTML = `
Token存在: <span class="success">是</span>
Token值: ${token}
用户类型: ${userType || '未设置'}
登录时间: ${loginTime ? new Date(parseInt(loginTime)).toLocaleString() : '未设置'}
Token长度: ${token.length}
                `;
            } else {
                tokenStatus.innerHTML = `
Token存在: <span class="error">否</span>
                `;
            }
            
            log('调试信息已刷新');
        }
        
        function clearAll() {
            localStorage.clear();
            log('已清除所有localStorage数据');
            refreshDebug();
        }
        
        function testTokenSave() {
            const testToken = 'test-token-' + Date.now();
            localStorage.setItem('token', testToken);
            localStorage.setItem('userType', '2');
            localStorage.setItem('loginTime', new Date().getTime().toString());
            log('测试Token已保存: ' + testToken);
            refreshDebug();
        }
        
        function testTokenRead() {
            const token = localStorage.getItem('token');
            if (token) {
                log('Token读取成功: ' + token);
            } else {
                log('Token读取失败: token不存在');
            }
        }
        
        // 页面加载时自动刷新
        window.onload = function() {
            refreshDebug();
            log('页面加载完成');
        };
        
        // 监听localStorage变化
        window.addEventListener('storage', function(e) {
            log(`localStorage变化: ${e.key} = ${e.newValue}`);
            refreshDebug();
        });
    </script>
</body>
</html>
